// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import './assets/stylus/reset.styl'
import 'element-ui/lib/theme-chalk/index.css'
import axios from 'axios'
import ElementUI from 'element-ui'
import store from './store/index'
import VueLazyLoad from 'vue-lazyload'
import vueInfiniteScroll from 'vue-infinite-scroll'
import './assets/css/iconfont.css'
import * as types from './store/mutations-types'
import srcollTo from './components/srcollTo_box/srcollTo_box'

Vue.use(ElementUI)
Vue.use(VueLazyLoad, {
   loading: require('../static/loading-svg/loading-bars.svg')
})
Vue.use(vueInfiniteScroll)

Vue.config.productionTip = false
Vue.prototype.$axios = axios

Vue.component('srcollTo', srcollTo)

router.beforeEach((to, from, next) => {
   let isRouter =  [
      '/iphomes',
      '/intelligentdevices',
      '/gamedevices',
      '/electronics',
      '/poweraccessories',
      '/mobilestorages',
      '/circums'
   ].some(itme => itme === to.path)
   if (isRouter) {
      store.commit(types.CLEAR_DATAILSPAGEDATA)
      store.commit(types.DISPLLAY_LOADING, true)
      store.commit(types.CLOSE_LAZYLOAD, {isClose: false})
      store.commit(types.SET_PARAMETER, {obj:{}})
   }
   if (from.path === '/register') {
      store.commit(types.BEFORE_ROUTER, '/')
   } else {
      store.commit(types.BEFORE_ROUTER, from.path)
   }

   let user_id =''
   if (document.cookie.split(';')[0].split('=')[0] === 'SESSION') {
      store.commit(types.LOGIN_STATE, true)
      user_id = window.sessionStorage.getItem('user_id')
      if (user_id) {
         store.commit(types.GET_USER, user_id)
      }
      next()
   } else {
      store.commit(types.LOGIN_STATE, false)
      next()
   }
})


/* eslint-disable no-new */
new Vue({
   el: '#app',
   router,
   store,
   components: {App},
   template: '<App/>'
})

